#!/usr/local/bin/python

import os,sys
import re
import time

if len(sys.argv) == 2:
    _dir = sys.argv[1]
else:
    _dir = os.getcwd()

threshold = 1024

dir_files = os.listdir(_dir)

psd_files = []
for f in dir_files:
    if f.endswith('.psd'):
       psd_files.append(f)

print "---------Width > 1024--------"
for f in psd_files: 
    fd = open(_dir+ "/" +f)
    d= fd.read()
    xmp_start = d.find('<x:xmpmeta')
    xmp_end = d.find('</x:xmpmeta')
    xmp_str = d[xmp_start:xmp_end+12]
    result = re.search('PixelXDimension>([0-9]*)', xmp_str)
    if result:
       res = result.group(1)
       if int(res) > threshold:
    	    print f

############## LAST MONTH ###################
print "-----Width > 1024 & Created within the last month----------"
for f in psd_files: 
    fd = open(_dir+ "/" +f)
    d= fd.read()
    xmp_start = d.find('<x:xmpmeta')
    xmp_end = d.find('</x:xmpmeta')
    xmp_str = d[xmp_start:xmp_end+12]
    result = re.search('PixelXDimension>([0-9]*)', xmp_str)
    if result:
       res = result.group(1)
       if int(res) > threshold:
         if ( os.stat(_dir+ "/" +f).st_ctime > (time.time() - (30 * 24 * 60 * 60))):
            print f

